//
//  OrderDetailViewController.m
//  AnnCar_user
//
//  Created by LiBenCan on 17/10/25.
//  Copyright © 2017年 LiBenCan. All rights reserved.
//

#import "OrderDetailViewController.h"
#import "DXCHeaderView.h"
#import "ChangeCell.h"
#import "StartCell.h"
#import "OrderSubmitCell.h"
#import "OrderChooseCell.h"
#import "ChooseTitleView.h"
#import "SelfTextView.h"
static NSString *const StartCellID = @"StartCellID";
static NSString *const OrderSubmitCellID = @"OrderSubmitCellID";
static NSString *const OrderChooseCellD = @"OrderChooseCellID";
@interface OrderDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableV;
@property (nonatomic,strong)NSArray *titleArr;//标题数组
@property (nonatomic,strong)ChooseTitleView *chooseView;//选择TiTleView
@property (nonatomic,strong)SelfTextView *textInputV;//输入框

@property (nonatomic,strong)UIButton *complainBtn;//投诉按钮
@property (nonatomic,strong)UIButton *trueBtn;//确认按钮

@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initTitleWithTitle:@"订单详情"];
    [self initLeftBarButtonWithImage:@"back"];
    [self.view addSubview:self.tableV];
    
    if (_statusNumber == 2) {//待验收
        [self.view addSubview:self.complainBtn];
        [self.view addSubview:self.trueBtn];
    }

    
}
//初始化标题数组
-(NSArray *)titleArr
{
    if(!_titleArr){
        if (_statusNumber == 0) {//待接单
            _titleArr = @[@[@"服务车辆",
                            @"车辆位置",
                            @"联系人",
                            @"备注信息",
                            ],
                          @[@"订单状态"]];
        }else if (_statusNumber == 1){//待洗车
            _titleArr = @[@[@"服务车辆",
                            @"车辆位置",
                            @"联系人",
                            @"手机号码",
                            @"精洗",
                            @"备注信息",
                            ],
                          @[@"订单编号",
                            @"订单状态",
                            @"洗车师傅",
                            @"师傅等级"]];
            
        }
        else if (_statusNumber == 2){//待验收
            _titleArr = @[@[@"服务车辆",
                            @"车辆位置",
                            @"精洗",
                            @"备注信息",
                            ],
                          @[@"订单状态",
                            @"师傅"],
                          @[@"评分",
                            @"choose"]
                          ];
            
        }
        else if (_statusNumber == 3){//已完成
            _titleArr = @[@[@"服务车辆",
                            @"车辆位置",
                            @"精洗",
                            @"备注信息",
                            ],
                          @[@"订单状态",
                            @"师傅"],
                          @[@"评分",
                            @"评价"]
                          ];
            
        }
       
    }
    return _titleArr;
}
//创建tableView
-(UITableView *)tableV
{
    if (!_tableV) {
        float tableHeight = SCREENH-64;
        if (_statusNumber == 2) {//待验收
            tableHeight = SCREENH-64-50*screenW_6;
        }
        _tableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0, SCREENW, tableHeight) style:UITableViewStyleGrouped];
        _tableV.backgroundColor = backColor;
        _tableV.rowHeight = 50*screenW_6;
        _tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableV.showsVerticalScrollIndicator = NO;
        [_tableV registerClass:[OrderSubmitCell class] forCellReuseIdentifier:OrderSubmitCellID];
        [_tableV registerClass:[OrderChooseCell class] forCellReuseIdentifier:OrderChooseCellD];
        [_tableV registerClass:[StartCell class] forCellReuseIdentifier:StartCellID];
        _tableV.delegate = self;
        _tableV.dataSource = self;
    }
    return _tableV;
}

#pragma Mark TableViewDelegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.titleArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ((indexPath.section ==2 && indexPath.row == 1 && _statusNumber == 2)) {
        return 80*screenW_6;
    }
    return 50*screenW_6;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return [self.titleArr[0] count];
    }else if (section == 1)
    {
       return [self.titleArr[1] count];
    }else
    {
        return [self.titleArr[2] count];
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section ==1 && _statusNumber == OrderDJD) {//待洗车
        return 145*screenW_6;
    }
    return 5*screenW_6;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if ((section ==2 && _statusNumber == 2)) {
        return 120*screenW_6;
    }
    else if (section == 2 && _statusNumber == 3)
    {
        return 50*screenW_6;
    }
    return 5*screenW_6;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    
    if ((indexPath.section ==1 && indexPath.row == 3 && _statusNumber == OrderDJD) || (indexPath.section ==2 && indexPath.row == 0 && _statusNumber == 2)) {//创建星星Cell
        StartCell *cell = [tableView dequeueReusableCellWithIdentifier:StartCellID forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell loadCell:@"评分" SecondStr:@"0"];
        return cell;
    }else if ((indexPath.section ==2 && indexPath.row == 1 && _statusNumber == 2))
    {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"chooseCell"];
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"chooseCell"];
        }
        _chooseView =[[ChooseTitleView alloc]initWithFrame:CGRectMake(0,0, SCREENW,80*screenW_6)];
        [cell addSubview:_chooseView];
        return cell;

    }
    else
    {
        
        ChangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChangeCell"];
        if (cell == nil) {
            cell = [[ChangeCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ChangeCell"];
        }
        [cell loadCellInputStr:@"安安洗车" PlaceHodelStr:@"" Title:self.titleArr[indexPath.section][indexPath.row]];
         return cell;
    }
   
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section ==1 && _statusNumber == OrderDJD) {//待洗车
        DXCHeaderView *dxcView =[[DXCHeaderView alloc]initWithFrame:CGRectMake(0,0,SCREENW,145*screenW_6)];
        return dxcView;
    }
    return nil;

}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section ==2 && _statusNumber == 2) {//待洗车
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 120*screenW_6)];
        view.backgroundColor = [UIColor whiteColor];
        _textInputV =[[SelfTextView alloc]initWithFrame:CGRectMake(15*screenW_6,0,SCREENW-30*screenW_6,100*screenW_6) PlaceHodel:@"说点什么吧～"];
        _textInputV.backgroundColor = _textInputV.TextV.backgroundColor = backColor;
        [view addSubview:_textInputV];
        return view;
        
    }else if (section == 2 && _statusNumber == 3){//已经完
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 50*screenW_6)];
        view.backgroundColor = [UIColor whiteColor];
        //展示评价内容
        UILabel *titleLab = [TomamaUI createLabel:CGRectMake(15*screenW_6, 10*screenW_6, SCREENW-30*screenW_6, 20*screenW_6) textAligment:0 font:[UIFont systemFontOfSize:15*screenW_6] textColor:TextGray text:@"洗的非常干净，棒棒的"];
        [view addSubview:titleLab];
        return view;
    }
    
    return nil;
}


//投诉
-(UIButton *)complainBtn
{
    if (!_complainBtn) {
        
        _complainBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _complainBtn.frame = CGRectMake(0, SCREENH-64-50*screenW_6, 150*screenW_6,50*screenW_6);
        [_complainBtn setTitle:@"投诉" forState:UIControlStateNormal];
        [_complainBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _complainBtn.backgroundColor = [UIColor colorWithHexString:@"#ff6000"];
//        [_complainBtn setImage:[UIImage imageNamed:@"My_pencil"] forState:UIControlStateNormal];
//        [_complainBtn setImageEdgeInsets:UIEdgeInsetsMake(15*screenW_6,SCREENW/2-50*screenW_6,15*screenW_6,SCREENW/2-30*screenW_6)];
//        [_complainBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,SCREENW/2-40*screenW_6,0,SCREENW/2-60*screenW_6)];
        [_complainBtn addTarget:self action:@selector(complainSelect) forControlEvents:UIControlEventTouchUpInside];
    
    }
    return _complainBtn;
}
//确认完成
-(UIButton *)trueBtn
{
    if (!_trueBtn) {
        
        _trueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _trueBtn.frame = CGRectMake(150*screenW_6, SCREENH-64-50*screenW_6,SCREENW-150*screenW_6,50*screenW_6);
        [_trueBtn setTitle:@"确认完成" forState:UIControlStateNormal];
        [_trueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _trueBtn.backgroundColor = blueColor;
        [_trueBtn addTarget:self action:@selector(complainSelect) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _trueBtn;
}

-(void)complainSelect//跳转投诉
{
    
}
@end

